home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / kernel / misc.c < prev    next >
C/C++ Source or Header  |  1990-07-15  |  4KB  |  129 lines

  1. /* This file contains a collection of miscellaneous procedures:
  2.  *    mem_init:    initialize memory tables.  Some memory is reported
  3.  *            by the BIOS, some is guesstimated and checked later
  4.  *    do_vrdwt:    unpack an i/o vector for those block device drivers
  5.  *            which do not do it for themself
  6.  */
  7.  
  8. #include "kernel.h"
  9. #include <minix/com.h>
  10.  
  11. #if (CHIP == INTEL)
  12.  
  13. #define EM_BASE     0x100000L    /* base of extended memory on AT's */
  14. #define SHADOW_BASE 0xFA0000L    /* base of RAM shadowing ROM on some AT's */
  15. #define SHADOW_MAX  0x060000L    /* maximum usable shadow memory (16M limit) */
  16.  
  17. /*=========================================================================*
  18.  *                mem_init                   *
  19.  *=========================================================================*/
  20. PUBLIC void mem_init()
  21. {
  22. /* Initialize the memory size tables.  This is complicated by fragmentation
  23.  * and different access strategies for protected mode.  There must be a
  24.  * chunk at 0 big enough to hold Minix proper.  For 286 and 386 processors,
  25.  * there can be extended memory (memory above 1MB).  This usually starts at
  26.  * 1MB, but there may be another chunk just below 16MB, reserved under DOS
  27.  * for shadowing ROM, but available to Minix if the hardware can be re-mapped.
  28.  * In protected mode, extended memory is accessible assuming CLICK_SIZE is
  29.  * large enough, and is treated as ordinary memory.
  30.  * The magic bits for memory types are:
  31.  *    1: extended
  32.  *    0x80: must be checked since BIOS doesn't and it may not be there.
  33.  */
  34.  
  35.   /* Get the size of ordinary memory from the BIOS. */
  36.   mem_size[0] = k_to_click(low_memsize);    /* 0 base and type */
  37.  
  38. #if SPARE_VIDEO_MEMORY
  39.   /* Spare video memory.  Experimental, it's too slow for program memory
  40.    * except maybe on PC's, and belongs low in a memory hierarchy.
  41.    */
  42.   if (color) {
  43.     mem_size[1] = MONO_SIZE >> CLICK_SHIFT;
  44.     mem_base[1] = MONO_BASE >> CLICK_SHIFT;
  45.   } else {
  46.     mem_size[1] = COLOR_SIZE >> CLICK_SHIFT;
  47.     mem_base[1] = COLOR_BASE >> CLICK_SHIFT;
  48.   }
  49.   mem_type[1] = 0x80;
  50. #endif
  51.  
  52.   if (pc_at) {
  53.     /* Get the size of extended memory from the BIOS.  This is special
  54.      * except in protected mode, but protected mode is now normal.
  55.      */
  56.     mem_size[2] = k_to_click(ext_memsize);
  57.     mem_base[2] = EM_BASE >> CLICK_SHIFT;
  58.  
  59.     /* Shadow ROM memory. */
  60.     mem_size[3] = SHADOW_MAX >> CLICK_SHIFT;
  61.     mem_base[3] = SHADOW_BASE >> CLICK_SHIFT;
  62.     mem_type[3] = 0x80;
  63.  
  64.     if (!protected_mode) {
  65.         mem_type[2] = 1;
  66.         mem_type[3] |= 1;
  67.     }
  68.   }
  69. }
  70. #endif /* (CHIP == INTEL) */
  71.  
  72.  
  73. /*==========================================================================*
  74.  *                do_vrdwt                    *
  75.  *==========================================================================*/
  76. PUBLIC int do_vrdwt(m_ptr, do_rdwt)
  77. register message *m_ptr;    /* pointer to read or write message */
  78. int (*do_rdwt)();        /* pointer to function which does the work */
  79. {
  80. /* Fetch a vector of i/o requests.  Handle requests one at a time.  Return
  81.  * status in the vector.
  82.  */
  83.  
  84.   register struct iorequest_s *iop;
  85.   static struct iorequest_s iovec[NR_BUFS];
  86.   phys_bytes iovec_phys;
  87.   unsigned nr_requests;
  88.   int request;
  89.   int result;
  90.   phys_bytes user_iovec_phys;
  91.   message vmessage;
  92.   int proc_nr;
  93.   int device;
  94.  
  95.   nr_requests = m_ptr->COUNT;
  96.   proc_nr = m_ptr->PROC_NR;
  97.   device = m_ptr->DEVICE;
  98.   if (nr_requests > sizeof iovec / sizeof iovec[0])
  99.     panic("FS gave some driver too big an i/o vector", nr_requests);
  100.   iovec_phys = umap(proc_ptr, D, (vir_bytes) iovec, (vir_bytes) sizeof iovec);
  101.   user_iovec_phys = numap(m_ptr->PROC_NR, (vir_bytes) m_ptr->ADDRESS,
  102.              (vir_bytes) (nr_requests * sizeof iovec[0]));
  103.   if (user_iovec_phys == 0)
  104.     panic("FS gave some driver bad i/o vector", (int) m_ptr->ADDRESS);
  105.   phys_copy(user_iovec_phys, iovec_phys,
  106.         (phys_bytes) nr_requests * sizeof iovec[0]);
  107.  
  108.   for (request = 0; request < nr_requests; ++request) {
  109.     iop = &iovec[request];
  110.     vmessage.m_type = iop->io_request & ~OPTIONAL_IO;
  111.     vmessage.DEVICE = device;
  112.     vmessage.PROC_NR = proc_nr;
  113.     vmessage.COUNT = iop->io_nbytes;
  114.     vmessage.POSITION = iop->io_position;
  115.     vmessage.ADDRESS = iop->io_buf;
  116.     result = (*do_rdwt)(&vmessage);
  117.     if (result == 0) break;    /* EOF */
  118.     if (result < 0) {
  119.         iop->io_nbytes = result;
  120.         if (iop->io_request & OPTIONAL_IO) break;  /* abort if opt */
  121.     } else
  122.         iop->io_nbytes -= result;
  123.   }
  124.  
  125.   phys_copy(iovec_phys, user_iovec_phys,
  126.         (phys_bytes) nr_requests * sizeof iovec[0]);
  127.   return(OK);
  128. }
  129.